﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Repository;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.Extensions.Logging;
using Model;
using Microsoft.AspNetCore.Mvc;

namespace WebApp.Controllers
{
    [Route("api/[controller]")]
    public class ValuesController : Controller
    {
        //public DbTest DbTest { get; private set; }
        private UserRepository _userRepository;
        private ILogger<ValuesController> _logger;
        private ILoggerFactory _loggerFactory;

        public ValuesController(
            UserRepository dbTest, 
            ILogger<ValuesController> logger, 
            ILoggerFactory loggerFactory)
        {
            _userRepository = dbTest;
            _logger = logger;
            _loggerFactory = loggerFactory;
            
        }

        // GET api/values
        [HttpGet]
        public IEnumerable<UserEntity> Get()
        {
            var startUp = HttpContext.RequestServices.GetService(typeof(IStartup));
            var list = _userRepository.GetList();
            _logger.LogError($"list.Count: {list.Count()}");
            _logger.LogDebug(1000, "logEvents");
            return list.ToArray();
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            return "value";
        }

        // POST api/values
        [HttpPost]
        public void Post([FromBody]string value)
        {
        }

        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
